Solving An Sql Interview Problem